import { useCallback } from 'react';
import { useSelector, useDispatch } from 'react-redux';
import AdminsApi from '../api/admins';
import Creators from '../store/actions';

export const useAdmins = () => {
    const adminsData = useSelector(state => state.adminsData);
    const dispatch = useDispatch()
    const { curPage, eachPage } = adminsData;
    const getAdmins = useCallback(async () => {
        const data = await AdminsApi.get({ curPage, eachPage })
        dispatch(Creators.getAdmins(data))
    }, [curPage, eachPage, dispatch])

    const setCurPage = useCallback(curPage => {
        dispatch(Creators.setCurPage({ curPage }))
    }, [dispatch])
    const setEachPage = useCallback(eachPage => {
        dispatch(Creators.setEachPage({ eachPage }))
    }, [dispatch])
    return [adminsData, { getAdmins, setCurPage, setEachPage }]
}